package com.csnf.mydatistest;

import com.csnf.dao.IStudentDao;
import com.csnf.dao.impl.StudentDaoImpl;
import com.csnf.entity.Student;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(name = "helloServlet", urlPatterns = "/hello-servlet")
public class HelloServlet extends HttpServlet {

    private String message;
    @Override
    public void init(){message = "Hello World!";}
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html");
        IStudentDao studentDao = new StudentDaoImpl();
        List<Student> all = studentDao.findAll();
        all.forEach(System.out::println);
        System.out.println("-------------------");
        System.out.println(studentDao.findById(1));


        // Hello
        PrintWriter out = response.getWriter();
        out.println("<html><body>");
        out.println("<h1>" + message + "</h1>");
        out.println("</body></html>");
    }
}
